package com.common.baselibrary.util;

import android.content.res.Resources;

/**
 * 尺寸转换工具类
 * Created by Administrator
 * 2019/10/17.
 */
public class DimensionHelper {

    public static int dip2px(float dipValue) {
        return (int) (dipValue * getDensity() + 0.5f);
    }

    public static int px2dip(float pxValue) {
        return (int) (pxValue / getDensity() + 0.5f);
    }

    public static int sp2px(float spValue) {
        return (int) (spValue * getScaledDensity() + 0.5f);
    }

    public static int px2sp(float pxValue) {
        return (int) (pxValue / getScaledDensity() + 0.5f);
    }

    public static float getDensity(){
        return Resources.getSystem().getDisplayMetrics().density;
    }

    public static float getScaledDensity(){
        return Resources.getSystem().getDisplayMetrics().scaledDensity;
    }
}